
package com.wobaby.security;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.wobaby.util.Constants;

// Referenced classes of package com.wobaby.security:
//            PermissionException, WebChecker, Checker, CLIChecker, 
//            PermissionMatrix, PermissionCache, UserPermissions, UserGroupPermissions, 
//            ViewPermissions, ViewablePartitions

public class Permission
{

    public Permission()
    {
    }

    public static void checkPermission(String resource, Integer userID,HttpServletRequest request)
        throws PermissionException
    {
        WebChecker.checkPermission(resource, userID, request);
    }

    public static void checkPermission(String resource, HttpServletRequest request)
        throws PermissionException
    {
        WebChecker.checkPermission(resource, request);
    }

    public static void checkPermission(String resource, Integer userID, Map input)
        throws PermissionException
    {
        Checker.checkPermission(resource, userID, input);
    }

    public static boolean hasPermission(String resource, Integer userID, Map input, StringBuffer denyMessage)
    {
        return WebChecker.hasPermission(resource, userID, input, denyMessage);
    }

    public static boolean hasPermission(String resource, HttpServletRequest request)
    {
        return WebChecker.hasPermission(resource, request);
    }

    public static boolean hasPermission(String resource, HttpServletRequest request, StringBuffer returnMessage)
    {
        return WebChecker.hasPermission(resource, request, returnMessage);
    }

    public static boolean hasPermission(String resource, Integer userID, Short userPrivLevel, HttpServletRequest request)
    {
        return WebChecker.hasPermission(resource, userID, request);
    }


    public static boolean hasPermissionForOtherObjects(String resource, Integer userID)
    {
        return Checker.hasPermissionForOtherObjects(resource, userID);
    }

    public static void checkRegularPermission(String resource, Integer userID)
        throws PermissionException
    {
        Checker.checkRegularPermission(resource, userID);
    }

    public static boolean hasRegularPermission(String resource, Integer userID)
    {
        return Checker.hasRegularPermission(resource, userID);
    }

    public static synchronized void reload()
    {
        PermissionMatrix.readPermissions();
    }


    public static boolean isAdministrator(Integer uid)
    {
        if(Constants.DEFAULT_ADMIN_USERID.equals(uid))
        {
            return true;
        } else
        {
            UserPermissions up = PermissionCache.getUserPermissions(uid);
            return up != null && up.isAdministrator();
        }
    }



    public static final String ADMINISTER_DEVICE_GROUPS = "Administer Device Groups";
    public static final String CREATE_SCRIPT_FROM_TEMPLATE = "Manage Command Script";
    public static final String MANAGE_TEMPLATE = "Manage Template";
    public static final String EDIT_DEVICE = "Edit Device";
    public static final String EDIT_TASK = "Edit Task";
    public static final String DELETE_DEVICE = "Delete Device";
    public static final String VIEW_FULL_DEVICE_CONFIGURATION = "View Full Device Configuration";
    public static final String VIEW_MASKED_DEVICE_CONFIGURATION = "View Device Configuration";
    public static final String MANAGE_CONFIGURATION_CONFIGURATION = "Manage Configuration Policy";
    public static final String ACTIVATE_DEVICE = "Activate/Deactivate Device";
    public static final String MANAGE_USER_ROLE = "Manage User Role";
    public static final String RESET_CONFIGURATION_ATTRIBUTOR = "Edit Config [Changed By] User";
    public static final String OVERRIDE_WORKFLOW_APPROVALS = "Override Workflow Approvals";
    public static final String ADMINISTER_USERS = "Administer Users";
    public static final String ADMINISTER_USER_GROUPS = "Administer User Groups";
}